import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import {Icon} from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from '../Pbulic.less';





@connect()
export default class EquipmentDetail extends PureComponent {
  constructor(props) {
    super(props);
  }


  componentDidMount() {

  }

  componentWillUnmount(){
    const { dispatch } = this.props;
    dispatch({
      type: `role/appendClearState`,
    })
  }




  formatterMenu = (data) => {
    return data.reduce((arr, curr) => {
      if(curr.authority){
        if (checkPermissions(curr.authority)) {
          return arr.concat(curr);
        } else {
          return arr.concat([]);
        }
      }else{
        return arr.concat(curr);
      }
    }, []);

  };

  goBack = () => {
    // this.props.onClose(0);
    const { dispatch, location, match } = this.props;
    router.push({ pathname:`/system/role/list`,  query: { ...location.query} });
  }

  render() {
    const { match, history, routerData,location, children } = this.props;

    const location_arry = history.location.pathname.split("/");
    const tabDefaultKeys = location_arry[location_arry.length - 1];
    const roleId = match.params.id && match.params.id!='detail' ? match.params.id : 0;

    // const tabDefaultTitle = [{title:tabList.find(item=>item.key==tabDefaultKeys).tab}];

    return (
      <Fragment>

        <Icon type="close-circle-o"  className={styles.close_icon} onClick={this.goBack}/>
          <PageHeaderLayout
            hiddenBreadcurmb={true}
            title={roleId==0 ? '新增角色' : '编辑角色'}
          >
            {children}
          </PageHeaderLayout>
      </Fragment>
    );
  }
}
